home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Commun⁄Network / RevRdist Folder / RevRdist / RevRdist src / pflags.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-08  |  4.9 KB  |  213 lines  |  [TEXT/KAHL]

  1. /*
  2.  * pflags.c - routines to set processing flags
  3.  */
  4.  
  5. #include "RevRdist.h"
  6. #include "TransSkelProto.h"
  7.  
  8. static DialogPtr        pfDialog;
  9.  
  10. static void pfEvent (Integer, EventRecord *);
  11. static void pfClose (void);
  12. static void pfClobber (void);
  13. static void pfGetFlags (void);
  14. static void pfSaveFlags (void);
  15. static void pfWatch (void);
  16.  
  17. /*
  18.  *=========================================================================
  19.  * setFlags () - set flags via modeless dialog
  20.  * entry:    SkelInit called, but not SkelMain
  21.  * exit:    Flags set
  22.  *=========================================================================
  23.  */
  24. void
  25. setFlags ()
  26. {
  27.     register Integer itemNo;        /* index to dialog items */
  28.     Integer            itemType;        /* for GetDItem call */
  29.     Handle            item;            /* " */
  30.     Rect            r;                /* " */
  31.     Integer            val;            /* value of individual flag bits */
  32.  
  33.     pfDialog = GetNewDialog (RSRC_BASE+WIND_FLAGS, nil, (WindowPtr) -1L);
  34.     if (pfDialog == nil)
  35.         return;
  36.     SkelDialog (pfDialog, (vProcPtr)pfEvent, (vProcPtr)pfClose, (vProcPtr)pfClobber);
  37.     /*
  38.      * Preset check boxes based on current Flag bit settings
  39.      */
  40.     for (itemNo = 3; itemNo < 3 + 31; itemNo++)
  41.     {
  42.         itemType = -1;
  43.         GetDItem (pfDialog, itemNo, &itemType, &item, &r);
  44.         if (itemType == (chkCtrl | ctrlItem))
  45.         {
  46.             val = (Flags >> (itemNo - 3)) & 1;
  47.             SetCtlValue ((ControlHandle) item, val);
  48.         }
  49.     }
  50.     ShowWindow ((WindowPtr) pfDialog);
  51.     SkelBackground (pfWatch);
  52.     SkelMain ();
  53. }
  54.  
  55.  
  56.  
  57. /*
  58.  *=========================================================================
  59.  * pfClobber () - get rid of the flags dialog resources
  60.  *=========================================================================
  61.  */
  62. void
  63. pfClobber ()
  64. {
  65.     if (pfDialog)
  66.         DisposDialog (pfDialog);
  67.     pfDialog = nil;
  68.     SkelWhoa ();
  69. }
  70.  
  71.  
  72. /*
  73.  *=========================================================================
  74.  * pfClose () - exit the flags dialog
  75.  * exit:    Flags set based on final control setting in dialog
  76.  *=========================================================================
  77.  */
  78. void
  79. pfClose ()
  80. {
  81.     pfGetFlags ();
  82.     SkelRmveDlog (pfDialog);
  83. }
  84.  
  85.  
  86. /*
  87.  *=========================================================================
  88.  * pfEvent (itemNo, theEvent) - handle events in flags dialog
  89.  * entry:    itemNo = the item number in dialog
  90.  *            theEvent = ptr to event record significant to dialog
  91.  *=========================================================================
  92.  */
  93. void
  94. pfEvent (itemNo, theEvent)
  95.     Integer            itemNo;
  96.     EventRecord *    theEvent;
  97. {
  98.     Integer            itemType;        /* dialog item type */
  99.     Handle            item;            /* dialog item structure */
  100.     Rect            r;                /* needed for GetDItem */
  101.     Integer            val;            /* control value */
  102.     Longint            l;                /* temp long value */
  103.  
  104.     if (itemNo == 1)
  105.     {
  106.         /*
  107.          * Okay button pushed, close dialog
  108.          */
  109.         pfClose ();
  110.         return;
  111.     }
  112.     if (itemNo == 2)
  113.     {
  114.         /*
  115.          * Save button pushed
  116.          */
  117.         pfGetFlags ();
  118.         pfSaveFlags ();
  119.         return;
  120.     }
  121.     /*
  122.      * The only other thing we are interested in is mouse downs in
  123.      * controls
  124.      */
  125.     if (theEvent->what == mouseDown && itemNo > 2)
  126.     {
  127.         itemType = -1;
  128.         GetDItem (pfDialog, itemNo, &itemType, &item, &r);
  129.         if (itemType == (chkCtrl | ctrlItem))
  130.         {
  131.             val = GetCtlValue ((ControlHandle) item);
  132.             SetCtlValue ((ControlHandle) item, !val);
  133.         }
  134.     }
  135. }
  136.  
  137.  
  138.  
  139. /*
  140.  *=========================================================================
  141.  * pfGetFlags() - set Flags based on current dialog checkboxes
  142.  * entry:    pfDialog set
  143.  * exit:    Flags updated
  144.  *=========================================================================
  145.  */
  146. static void
  147. pfGetFlags (void)
  148. {
  149.     Integer            itemNo;            /* dialog item number */
  150.     Integer            itemType;        /* dialog item type */
  151.     Handle            item;            /* dialog item */
  152.     Rect            r;                /* needed for GetDItem */
  153.     Integer            val;
  154.  
  155.     Flags = 0;
  156.     for (itemNo = 3; itemNo < 3 + 31; itemNo++)
  157.     {
  158.         itemType = -1;
  159.         GetDItem (pfDialog, itemNo, &itemType, &item, &r);
  160.         if (itemType == (chkCtrl | ctrlItem))
  161.         {
  162.             val = GetCtlValue ((ControlHandle) item);
  163.             Flags |= val << (itemNo - 3);
  164.         }
  165.     }
  166. }
  167.  
  168.  
  169. /*
  170.  *=========================================================================
  171.  * pfSaveFlags() - modify RevRdist processing flags resource
  172.  * entry:    Flags = new value for processing flags resource
  173.  *            Ap_refNum = refNum of application resource fork
  174.  * exit:    resource updated
  175.  *=========================================================================
  176.  */
  177. static void
  178. pfSaveFlags (void)
  179. {
  180.     Handle            h;                /* ptr to flags resource */
  181.     Integer            oldres;            /* resource refnum */
  182.  
  183.     oldres = CurResFile();
  184.     UseResFile (Ap_refNum);
  185.     h = Get1Resource (TYPE_LONG, FLAG_PARM);
  186.     if (h)
  187.     {
  188.         if (GetHandleSize (h) >= sizeof (Flags))
  189.         {
  190.             BlockMove ((Ptr) &Flags, *h, sizeof (Flags));
  191.             ChangedResource (h);
  192.             WriteResource (h);
  193.         }
  194.         ReleaseResource (h);
  195.     }
  196.     UseResFile (oldres);
  197. }
  198.  
  199. /*
  200.  *=========================================================================
  201.  * pfWatch () - watch for Quit
  202.  *=========================================================================
  203.  */
  204. void
  205. pfWatch ()
  206. {
  207.     if (Quit)
  208.     {
  209.         SkelBackground (nil);
  210.         pfClose ();
  211.     }
  212. }
  213.